﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace GRMS.App_Code
{
    public class ActionEventDefination
    {
        #region Properties
        public string ID;
        public string Value;
        #endregion

        #region Constructors
        public ActionEventDefination()
        {
            this.ID = "";
            this.Value = "";
        }
        public ActionEventDefination(string id, string value)
        {
            this.ID = id;
            this.Value = value;
        }
        #endregion
    }

    public class ActionEventLibrary
    {
        #region Properties
        private Dictionary<string, ActionEventDefination> LoadedActions;
        private string filename;
        private Session current;
        #endregion

        #region Constructors
        public ActionEventLibrary(string filename, Session current)
        {
            this.filename = filename;
            this.current = current;
            LoadedActions = new Dictionary<string, ActionEventDefination>();
        }
        #endregion

        #region Methods
        public string GetActionEventDefination(string action)
        {
            if (!LoadedActions.ContainsKey(action))
                LoadedActions.Add(action, GetXML(action));
            return LoadedActions[action].Value;
        }
        private ActionEventDefination GetXML(string action)
        {
            Hashtable ht1 = XMLReader.GetValueFrom(filename, "actionEventLibrary check", action, current);
            Hashtable ht2 = (Hashtable)ht1[action];
            string Action = ht2[action].ToString();

            return new ActionEventDefination(action, Action);
        }
        #endregion
    }
}
